<?php
namespace app\admin\controller;

\think\Loader::import('controller/Controller', \think\Config::get('traits_path') , EXT);

use app\admin\Controller;
use think\Db;
use think\Request;
use think\Validate;

class Arctic extends Controller
{
    use \app\admin\traits\controller\Controller;
    // 方法黑名单
    protected static $blacklist = [];


    /**
     * 添加车型
     * url: /admin/arctic/add
     */

    public function add(Request $request)
    {
        if ($request->isPost()){
            $postData = $request->post(); // 接收数据
            // 验证数据
            $rule = [
                'name' => 'require',
            ];
            $message = [
                'name.require' => '车辆类型名称不能为空',
            ];
            $validate = new Validate($rule,$message);
            $result = $validate->check($postData);
            if (!$result){
                return ajax_return_error($validate->getError());
            }
            $postData['create_time'] = time();
            // 保存数据
            $addData = Db::name('arctic')->strict(false)->insertGetId($postData);
            if ($addData){
                return ajax_return_adv('添加成功');
            }else{
                return ajax_return_error('添加失败');
            }
        }else{
            return view('edit');
        }
    }
    
    /**
     * 获取车型列表
     */
    public function index()
    {
        $data = input();
        if ($data['name']) {
            $map['name'] = ['like',"%{$data['name']}%"];
        }
        if ($this::$isdelete){
            $map['isdelete'] = 1;
        }else{
            $map['isdelete'] = 0;
        }
        if ($data['create_time']){
            $start_time = "{$data['create_time']} 0:0:0"; //开始时间
            $end_time = "{$data['create_time']} 23:59:59"; // 结束时间
            $map['create_time'] = ['between',[strtotime($start_time),strtotime($end_time)]];
        }
        $list = Db::name('arctic')->where($map)->order('id','desc')->paginate();
        $count = $list->total();
        return view('',compact('list','count'));
    }

    /**
     *
     */
}
